<?php

class Site_ArticleController extends Fengqiaoju_Controller_Action {

	public function init() {

		parent::init ();
		$this->view->site_id = $this->site_id = $this->_request->getParam ( 'site_id' );
		$this->site_seo_name = $this->_request->getParam ( 'site_seo_name' );
		$this->view->model_id = $this->_request->getParam ( 'model_id' );
		$this->model_seo_name = $this->_request->getParam ( 'model_seo_name' );
		$this->view->article_id = $this->_request->getParam ( 'id' );
		$this->view->page_id = $this->_request->getParam ( 'page_id' );
	}

	public function indexAction() {

		$numPerPage = 10;
		$page = $this->view->page_id ? $this->view->page_id : 1;
		$offset = $numPerPage * intval($page-1);
		
		$modelObject = new Site_Models_Model ();
		$articleObject = new Site_Models_Article ();
		$siteObject = new Site_Models_Site ();
		
		//当前模块信息
		$where = array ();
		$where = "model_id=" . intval ( $this->view->model_id );
		$this->view->modelInfo = $modelObject->fetchRow ( $where );
		
		if (! $this->view->modelInfo ['model_id']) {
			$this->message ( '您访问的模块不存在' );
		}
		
		//头部导航菜单
		$where = array ();
		$where = 'site_id = ' . intval ( $this->view->modelInfo ['site_id'] );
		$this->view->modelList = $modelObject->fetchAll ( $where );
		
		//文章列表
		$where = array ();
		$where = 'model_id=' . intval ( $this->view->model_id );
		$this->view->articleList = $articleObject->fetchAll ( $where, 'article_updatetime DESC', $numPerPage, $offset );
		$paginator = Zend_Paginator::factory ( $articleObject->fetchAll ( $where ) );
		$paginator->setCurrentPageNumber ( $page )->setItemCountPerPage ( $numPerPage );
		$this->view->paginator = $paginator;
		
		//小站信息
		$where = array ();
		$where = "site_id=" . $this->view->modelInfo ['site_id'];
		$this->view->siteInfo = $siteObject->fetchRow ( $where );
		$this->view->description = strip_tags ( $this->view->modelInfo ['model_intro'] ) . "," . $this->view->modelInfo ['model_name'] . '_' . $this->view->siteInfo ['site_name'] . "-" . $this->config ['site'] ['title'];
		$this->view->keywords = $this->view->modelInfo ['model_name'] . ',' . $this->view->modelInfo ['model_name'] . '信息,' . $this->view->siteInfo ['site_name'] . "," . $this->config ['site'] ['title'];
		;
		$this->view->title = $this->view->modelInfo ['model_name'] . '_' . $this->view->siteInfo ['site_name'] . "-" . $this->config ['site'] ['title'];
	
	}

	/**
	 * 显示文章
	 */
	public function showAction() {

		$modelObject = new Site_Models_Model ();
		$articleObject = new Site_Models_Article ();
		$siteObject = new Site_Models_Site ();
		
		//文章内容
		$where = array ();
		$where = "article_id=" . intval ( $this->view->article_id );
		$this->view->articleInfo = $articleObject->getArticleInfo ( $where );
		
		//头部导航菜单
		$where = array ();
		$where = 'site_id = ' . intval ( $this->view->articleInfo ['site_id'] );
		$this->view->modelList = $modelObject->fetchAll ( $where );
		
		//当前模块信息
		$where = array ();
		$where = "model_id=" . $this->view->articleInfo ['model_id'];
		$this->view->modelInfo = $modelObject->fetchRow ( $where );
		
		//小站信息
		$where = array ();
		$where = "site_id=" . $this->view->modelInfo ['site_id'];
		$this->view->siteInfo = $siteObject->fetchRow ( $where );
		
		//文章列表
		$where = '';
		$where = ' article_id<>' . intval ( $this->view->article_id ) . ' AND model_id = ' . intval ( $this->view->articleInfo ['model_id'] );
		$this->view->newArticleList = $articleObject->fetchAll ( $where, 'article_updatetime desc ', 10 );
		
		$this->view->title = $this->view->articleInfo ['article_title'] . '_' . $this->view->modelInfo ['model_name'] . '_' . $this->view->siteInfo ['site_name'] . "-" . $this->config ['site'] ['title'];
		$this->view->model_id = $this->view->articleInfo ['model_id'];
		
		//评论
		$this->commentObject = new Site_Models_Comment ();
		$this->view->userObject = $this->userObject;
		$where = "model_type='article' AND item_id=" . intval ( $this->view->article_id );
		$this->view->comment = $this->commentObject->fetchAll ( $where, 'comment_inputtime DESC', 20, 0 );
	
	}
}